import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { BasicSimpleEntity } from '../../common/entities/basic.simple.entity';
import { OrganizationEntity } from '../../organization/entities/organization.entity';
import { UserType } from '../../role/constants/role.constant';
import { RoleEntity } from '../../role/entities/role.entity';

@Entity('users')
export class UserEntity extends BasicSimpleEntity {
  @PrimaryGeneratedColumn('uuid')
  uuid: string;

  @Column('int', { name: 'job_id', comment: '用户当前岗位/组织的id', nullable: true })
  jobId: number;

  @Column('enum', { enum: UserType, comment: '用户类型', default: UserType.user })
  type: UserType;

  @Column('varchar', { comment: '登录账户' })
  username: string;

  @Column('varchar', { name: 'display_name', comment: '显示名称', nullable: true })
  displayName: string;

  @Column('varchar', { comment: '密码（MD5加密）', select: false })
  password: string;

  @Column('varchar', { comment: '邮箱地址', nullable: true })
  email: string;

  @Column('varchar', { comment: '手机号码', nullable: true })
  mobile: string;

  @Column('varchar', { name: 'avatar_url', comment: '用户头像', nullable: true })
  avatarUrl: string;

  @Column('boolean', { comment: '账号是否启用', default: true })
  active: boolean;

  @Column('uuid', { array: true, name: 'role_uuid_list', comment: '角色Uuid列表' })
  roleUuidList: string[];

  roleList: RoleEntity[];

  @Column('int', { array: true, name: 'organization_id_list', comment: '用户组织id列表' })
  organizationIdList: number[];

  organizationList: OrganizationEntity[];
}
